package cn.edu.scnu.rabbitmq.test;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.junit.Before;
import org.junit.Test;

public class FanoutMode {
    private Channel channel;

    @Before
    public void initChannel() throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.126.129");
        factory.setPort(5672);
        factory.setUsername("guest");
        factory.setPassword("guest");
        factory.setVirtualHost("/");
        Connection connection = factory.newConnection();
        channel = connection.createChannel();
    }

    @Test
    public void send() throws Exception {
        channel.exchangeDeclare("Test01", "fanout");

        channel.queueDeclare("Test1", false, false, false, null);
        channel.queueDeclare("Test2", false, false, false, null);
        channel.queueDeclare("Test3", false, false, false, null);

        channel.queueBind("Test1", "Test01", "");
        channel.queueBind("Test2", "Test01", "");
        channel.queueBind("Test3", "Test01", "");

        channel.basicPublish("Test01", "", null, "TestStringFanout".getBytes());
    }
}
